package com.shdaily.android;

import java.net.MalformedURLException;
import java.net.URL;

import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;

public class ArticleActivity extends Activity {
	
	Bundle bundle = this.getIntent().getExtras();
	String id = bundle.getString("id");
	String title = bundle.getString("title");
	String summary = bundle.getString("summary");
	String author = bundle.getString("author");
	String body = bundle.getString("body");
	String date = bundle.getString("date");
	String hasPic = bundle.getString("hasPic");
	String imageURLs = bundle.getString("imageURLs");
	EngineDB db = new EngineDB(getApplicationContext());
	
	@Override
	protected void onCreate(Bundle icicle) {
		try {
			super.onCreate(icicle);
			Display display = getWindowManager().getDefaultDisplay();
			int width = display.getWidth();
			int height = display.getHeight();
			
			ArticleView artView = new ArticleView(this.getApplicationContext(), 
					id, title, summary, author, body, date, hasPic, width);
			setContentView(artView);

		} catch (Exception e) {
			Log.e("SHDaily exception: ",e.toString());
		}
		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {    
		MenuInflater inflater = getMenuInflater();    
		inflater.inflate(R.menu.article_menu, menu);    
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {    
		// Handle item selection    
		switch (item.getItemId()) {    
			case R.id.favorite:        
				addToFavorites();        
				return true;    
			case R.id.share:        
				share();        
				return true;   
			case R.id.fontincrease:        
				//showHelp();        
				return true;
			case R.id.fontdecrease:        
				//showHelp();        
				return true;
			default:        
				return super.onOptionsItemSelected(item);    
		}
	}
	
	public void addToFavorites()
	{
		Article article = new Article();
		article.setId(Integer.parseInt(id));
		article.setTitle(title);
		article.setSummary(summary);
		article.setDate(date);
		article.setHasPic(Integer.parseInt(hasPic));
		article.setBody(body);
		
	}
	
	public void share()
	{
		Article article = new Article();
		article.setId(Integer.parseInt(id));
		article.setTitle(title);
		article.setSummary(summary);
		article.setDate(date);
		article.setHasPic(Integer.parseInt(hasPic));
	}
	
	

}
